package com.lcxw.hxzbadmin.configcontroller;

import com.lcxw.hxzbadmin.entity.requestbean.RequestBodyBasic;
import com.lcxw.hxzbadmin.entity.requestbean.UpdateProp;
import com.lcxw.hxzbapi.entity.pojo.Proportion;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.ProportionService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/proportion")
public class ProportionController {

    @Resource
    ProportionService proportionService;

    @PostMapping("/get")
    public Response getProportion(@RequestBody RequestBodyBasic requestBodyBasic) {

        return Response.ok(proportionService.getPropForAdmin());
    }

    @PostMapping("/update")
    public Response updateProp(@RequestBody UpdateProp updateProp) {
        double ordinaryProp = updateProp.getOrdinaryProp() / 100;
        double unionProp = updateProp.getUnionProp() / 100;
        double ordinaryTax = updateProp.getOrdinaryTax() / 100;
        Proportion prop = proportionService.getProp();
        prop.setOrdinaryProp(ordinaryProp);
        prop.setUnionProp(unionProp);
        prop.setOrdinaryTax(ordinaryTax);
        proportionService.updateProportion(prop);
        return Response.ok();
    }

}
